package com.muqi.app.qlearn.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easemob.easeui.widget.CircularImage;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.project.contants.MContants;
import com.muqi.app.qlearn.modles.PersonBean;
import com.muqi.app.qlearn.modles.StatisticsInfo;
import com.muqi.app.qlearn.modles.StatisticsListInfo;
import com.muqi.app.qlearn.student.R;

import com.muqi.app.user.widget.CircularImageView;
import com.muqi.app.user.widget.SelectableRoundedImageView;

public class ClassRoomCommentStatisticsAdapter extends BaseAdapter {
	private Context context;
	private List<StatisticsListInfo> listData;

	// private int[] makerBackground = new
	// int[]{R.drawable.maker_bg_blue,R.drawable.maker_bg_purple,R.drawable.maker_bg_red,R.drawable.maker_bg_yellow};

	public ClassRoomCommentStatisticsAdapter(Context context,
			List<StatisticsListInfo> listData) {
		this.context = context;
		this.listData = listData;
	}

	@Override
	public int getCount() {
		return listData == null ? 10 : listData.size();
	}

	@Override
	public StatisticsListInfo getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		StatisticsListInfo info = listData.get(position);

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_classromm_comment_statistics_list, null);
			holder.itemLine = (ImageView) convertView
					.findViewById(R.id.item_line);
			holder.itemAvatar = (CircularImageView) convertView
					.findViewById(R.id.item_avator);
			holder.itemName = (TextView) convertView
					.findViewById(R.id.item_name);
			holder.itemTime = (TextView) convertView
					.findViewById(R.id.item_time);
			holder.itemMe=(TextView) convertView.findViewById(R.id.item_me);
			holder.itemType = (ImageView) convertView
					.findViewById(R.id.item_type);
			holder.itemIntrooduce = (TextView) convertView
					.findViewById(R.id.item_introduce);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.itemTime.setText(info.create_time);
		if (position == 0) {
			holder.itemLine.setImageResource(R.drawable.statistics_white_green);
		} else {
			holder.itemLine.setImageResource(R.drawable.statistics_white_line);
		}

		if (info.from_userInfo != null) {
			GlideImageUtils
					.setAvatar(context,
							info.from_userInfo.avatarInfo.fileurl_02,
							holder.itemAvatar);
			//holder.itemName.setText(info.from_userInfo.name);
		}
		if(info.to_userInfo!=null){
			holder.itemName.setText(info.to_userInfo.name);
		}
		holder.itemIntrooduce.setText(info.title);
		/*if (info.title.contains("举手发言")) {
			holder.itemType.setImageResource(R.drawable.statistics_hand);
			holder.itemIntrooduce.setText(info.title);
			holder.itemIntrooduce.setTextColor(context.getResources().getColor(R.color.statis_hand));

		} else if (info.title.contains("课后复习")) {
			holder.itemType.setImageResource(R.drawable.statistics_review);
			holder.itemIntrooduce.setText(info.title);
			holder.itemIntrooduce.setTextColor(context.getResources().getColor(R.color.statis_review));

		} else if (info.title.contains("认真听讲")) {
			holder.itemType.setImageResource(R.drawable.statistics_listener);
			holder.itemIntrooduce.setText(info.title);
			holder.itemIntrooduce.setTextColor(context.getResources().getColor(R.color.statis_listener));

		} else if (info.title.contains("善于思考")) {
			holder.itemType.setImageResource(R.drawable.statistics_think);
			holder.itemIntrooduce.setText(info.title);
			holder.itemIntrooduce.setTextColor(context.getResources().getColor(R.color.statis_think));
			
		}else{
			if(info.title.contains("捣乱")){
				holder.itemMe.setText("批评我");
			}
			holder.itemType.setImageBitmap(null);
			holder.itemIntrooduce.setText(info.title);
			holder.itemIntrooduce.setTextColor(context.getResources().getColor(R.color.statis_text_item_color));
			
		}*/
		//holder.itemIntrooduce.setText(info.title);
		return convertView;
	}

	private class ViewHolder {
		TextView itemTime;
		ImageView itemLine;
		CircularImageView itemAvatar;
		TextView itemName;
		TextView itemMe;
		ImageView itemType;
		TextView itemIntrooduce;

	}
}
